package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.erp.R
import com.erp.bean.PieceworkcollBean
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_piecework_chaxun.view.*


class PiecewrokChaxunAdapter(private val mlist: List<PieceworkcollBean>, private val mcontext: Context) : BaseAdapter(){
    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)

    private var code : Int = 1
    fun setCode(code : Int){
        this.code = code
    }

    override fun getCount(): Int {
        return mlist.size
    }

    override fun getItem(position: Int): Any {
        return mlist[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v : View
        val h: ViewHolder
        if (convertView == null) {
            v = minflater.inflate(R.layout.lv_piecework_chaxun, null)
            h = ViewHolder(v)
            v.tag = h
        } else {
            v=convertView
            h = convertView.tag as ViewHolder
        }
        var bean = mlist[position]
//        Myutil.settv("岗位："+bean.gangwei_name,h.TvGangwei)
//        Myutil.settv("项目："+bean.xm,h.TvXiangmu)
        if(code == 1){
            Myutil.settv("时间："+bean.pcoll_at,h.TvCreatedAt)
        }else if(code == 2){
            Myutil.settv("日期："+bean.pcoll_at_md,h.TvCreatedAt)
        }else if(code == 3){
            Myutil.settv("月份："+bean.pcoll_at_m,h.TvCreatedAt)
        }
        Myutil.settv("成员："+bean.worker_group,h.TvWorkerGroup)
//        Myutil.settv("采集说明："+bean.content_cat,h.TvContentCat)
        if(code == 1){
            Myutil.settv("节号："+bean.batch_names,h.TvBatchName)
            Myutil.settv("平方："+bean.square,h.TvSquare)
            Myutil.settv("件数："+bean.mcount,h.TvMcount)
            Myutil.settv("包条码："+bean.pcode,h.TvPcode)
            h.TvBatchName.visibility = View.VISIBLE
            h.TvSquare.visibility = View.VISIBLE
            h.TvMcount.visibility = View.VISIBLE
            h.TvPcode.visibility = View.VISIBLE
            h.TvPcount.visibility = View.GONE
            h.TvSumSquare.visibility = View.GONE
            h.TvSumMcount.visibility = View.GONE
        }else{
            h.TvBatchName.visibility = View.GONE
            h.TvSquare.visibility = View.GONE
            h.TvMcount.visibility = View.GONE
            h.TvPcode.visibility = View.GONE
        }
        if(code != 1){
            Myutil.settv("汇总包数："+bean.pcount,h.TvPcount)
            Myutil.settv("汇总平方："+bean.sum_square,h.TvSumSquare)
            Myutil.settv("汇总件数："+bean.sum_mcount,h.TvSumMcount)
            h.TvBatchName.visibility = View.GONE
            h.TvSquare.visibility = View.GONE
            h.TvMcount.visibility = View.GONE
            h.TvPcode.visibility = View.GONE
            h.TvPcount.visibility = View.VISIBLE
            h.TvSumSquare.visibility = View.VISIBLE
            h.TvSumMcount.visibility = View.VISIBLE
        }else{
            h.TvPcount.visibility = View.GONE
            h.TvSumSquare.visibility = View.GONE
            h.TvSumMcount.visibility = View.GONE
        }
        return  v;
    }

    internal class ViewHolder(v: View) {
//        var TvGangwei: TextView
//        var TvXiangmu: TextView
        var TvCreatedAt: TextView
        var TvWorkerGroup: TextView
//        var TvContentCat: TextView
        var TvBatchName: TextView
        var TvSquare: TextView
        var TvMcount: TextView
        var TvPcode: TextView
        var TvPcount: TextView
        var TvSumSquare: TextView
        var TvSumMcount: TextView
        init {
//            TvGangwei = v.TvGangwei
//            TvXiangmu = v.TvXiangmu
            TvCreatedAt = v.TvCreatedAt
            TvWorkerGroup = v.TvWorkerGroup
//            TvContentCat = v.TvContentCat
            TvBatchName = v.TvBatchName
            TvSquare = v.TvSquare
            TvMcount = v.TvMcount
            TvPcode = v.TvPcode
            TvPcount = v.TvPcount
            TvSumSquare = v.TvSumSquare
            TvSumMcount = v.TvSumMcount
        }
    }
}